package com.future.Config;


import com.future.handler.MyAuthenticationSuccessHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception{
        http.formLogin()
                .usernameParameter("userHao")
                .passwordParameter("userPwd")
                //自定义登陆页面
                .loginPage("/loginpage");
//                .successForwardUrl("/future");
//        授权认证
        http.authorizeRequests()
//        不要被认证
//                .antMatchers("/").permitAll()
//        所有请求都需要被认证
                .antMatchers("/**").permitAll()
//                .regexMatchers().permitAll()
//                .mvcMatchers("/login").servletPath("/future").permitAll()
                .anyRequest().authenticated();

        //关闭防火墙
        http.csrf().disable();
    }


    @Bean
    public PasswordEncoder getPw(){
        return new BCryptPasswordEncoder();
    }


}
